﻿/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author Oplink OMS
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webems.modules.log.dao;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.oplink.webems.common.persistence.BaseDao;
import com.oplink.webems.common.persistence.BaseDaoImpl;


import com.oplink.webems.modules.log.entity.UserLog;

/**
 * 告警DAO接口
 * @author Oplink OMS
 * @version 2014-09-09
 */
public interface UserLogDao extends UserLogDaoCustom, CrudRepository<UserLog, Long> {

	@Modifying
	@Query("update UserLog set delFlag='" + UserLog.DEL_FLAG_DELETE + "' where id = ?1")
	public int deleteById(Long id);
	
}

/**
 * DAO自定义接口
 * @author Oplink OMS
 */
interface UserLogDaoCustom extends BaseDao<UserLog> {
	public int saveLog(UserLog ul);
}

/**
 * DAO自定义接口实现
 * @author Oplink OMS
 */
@Component
class UserLogDaoImpl extends BaseDaoImpl<UserLog> implements UserLogDaoCustom {

	@Override
	public int saveLog(UserLog ul) {
		/*String hql = "insert into com.oplink.webems.modules.log.entity.UserLog (module,desc,params,time,user_id) values(?,?,?,?,?)";
		org.hibernate.Query q = this.getSession().createQuery(hql);
		q.setParameter(0, ul.getModule());
		q.setParameter(1, ul.getDesc());
		q.setParameter(2, ul.getParams());
		q.setParameter(3, ul.getTime());
		q.setParameter(4, ul.getUser().getId());
		int ret = q.executeUpdate();*/
		this.getSession().save(ul);
		return 1;
	}

}